home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
EXAMP402.CPP
< prev
next >
Wrap
Text File
|
1992-05-12
|
1KB
|
42 lines
// examp402.cpp - link with binder.obj
#include <string.h>
#include <iostream.h>
struct str {
char *s;
str(const char *cs = (char *)0) // default constructor
{ s = (cs? strdup(cs) : (char *)0); }
str(str& si) // copy initialize
{ s = (si.s? strdup(si.s) : si.s); }
void operator=(str& si) // assignment
{ delete s; s = (si.s? strdup(si.s) : si.s); }
void operator=(const char * cs)
{ delete s; s = (cs? strdup(cs) : (char *)0); }
~str() { delete s; } // destructor
};
ostream& operator<<(ostream& os, str&)
{ return os; }
istream& operator>>(istream& is, str&)
{ return is; }
#include "tbinder.hpp"
TBINDER(str,StrBdr,StrBdR);
main()
{
StrBdr sb(BDR_DDELETE);
sb.ins(new str("line one"));
str s("Why won't this string appear in the Binder?");
sb.insNew(&s);
s = "line two";
sb.setFlags(BDR_DNEW);
sb.insNew(&s);
sb.setCurNode(); // reset current node
while (sb.next()) cout << ((str *)sb)->s << "\n";
return 0;
}